package vip.xiaonuo.smzq.modular.user.controller;

import javax.annotation.Resource;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import vip.xiaonuo.smzq.modular.user.entity.Position;
import vip.xiaonuo.smzq.modular.user.service.IPositionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import vip.xiaonuo.common.pojo.CommonResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * 职位
 *
 * @author sqq
 * @since 2024-04-22
 */
@Api(tags = "职位")
@RestController
@RequestMapping("/user/position")
@Validated
public class PositionController {

    @Resource
    private IPositionService iPositionService;

    /**
     * 添加职位
     */
    @ApiOperation("添加职位")
    @PostMapping("/add")
    public CommonResult<String> add(@RequestBody @Valid Position position) {
        iPositionService.save(position);
        return CommonResult.ok();
    }

    /**
     * 删除职位
     */
    @ApiOperation("删除职位")
    @PostMapping("/delete")
    public CommonResult<String> delete(@ApiParam(name = "pkid", value = "主键") @RequestParam String pkid) {
        iPositionService.removeById(pkid);
        return CommonResult.ok();
    }

    /**
     * 编辑职位
     */
    @ApiOperation("编辑职位")
    @PostMapping("/edit")
    public CommonResult<String> edit(@RequestBody @Valid Position position) {
        iPositionService.updateById(position);
        return CommonResult.ok();
    }

    /**
     * 职位分页查询
     */
    @ApiOperation("职位分页查询")
    @GetMapping("/list")
    public CommonResult<Page<Position>> page() {
        return CommonResult.data(iPositionService.page(new Position()));
    }
}
